/********************************
 * ETK - Easy ToolKit
 * Copyright (C) 2007-2008 Ekinoks (scv.ekinoks@gmail.com)
 * All rights reserved.
 *
 *    This file is part of ETK.
 *
 *    Foobar is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    Foobar is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Foobar; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 ***********************************************************************************/

#include "Window.h"

#include <gtk/gtk.h>

#include "../../../Render/Render.h"
#include "../../../Render/ToolKit/ToolKit.h"
#include "../../../define.h"
#include "../../../CallBack/CallBack.h"
#include "../../../CallBack/LIST_EVENT.H"

#include "../../Widget.h"
#include "../Box/Box.h"

namespace etk
{
    void Window::init(const int size_x, const int size_y, const int positionX, const int positionY)
    {
        // La taille
        setSize(size_x, size_y);

        // La position
        setPosition(positionX, positionY);

        // Création d'une box pour contenir les differant element
        container = NULL;
        container = new Box(this);

        // On bind la croix
        new CallBackT<Event>(this, EVENT_DELETE, boost::bind(&Widget::destroy, _ME), true);
    }

    Window::Window(const char * title, int size_x, int size_y, int positionX, int positionY) : WidgetContainer(TOOL_KIT.window_new(), NULL), container(NULL)
    {
        init(size_x, size_y, positionX, positionY);

        // on rajoute le titre
        setTitle(title);
    }

    Window::Window(int size_x, int size_y, int positionX, int positionY) : WidgetContainer(TOOL_KIT.window_new(), NULL), container(NULL)
    {
        init(size_x, size_y, positionX, positionY);
    }

    Widget* Window::add(Widget* widget)
    {
        if(container!=NULL)
            container->add(widget);
        else
            TOOL_KIT.container_add(getRWidget(), widget->getRWidget()); // Window est un exception, car c'est lui meme qui se charge de gerer sont contenue

        return widget;
    }


    void Window::remove(Widget* widget)
    {
        if(widget == this)
            return;

        if(widget==container)
            container = NULL;
        else
            container->remove(widget);
    }

    Window::~Window()
    {
        start_section("~Window");
        delete container;
        end_section("~Window");
    }


    //////////////////////////// MODIFIEUR ////////////////////////////////
    Window * Window::setTitle(const char * title)
    {
        TOOL_KIT.window_set_title(getRWidget(), title);
        return this;
    }

    Window * Window::setSize(const int size_x, const int size_y)
    {
        TOOL_KIT.window_set_size(getRWidget(), size_x, size_y);
        return this;
    }

    Window * Window::setPosition(const int positionX, const int positionY)
    {
        TOOL_KIT.window_set_position(getRWidget(), positionX, positionY);
        return this;
    }
    ///////////////// FIN MODIFIEUR /////////////////
}



